<?php

namespace App\Models\Applet\Sponsor;

class SlaughterSendBackRecordsModel extends BaseSponsorModel
{
    protected $table = 'slaughter_send_back_records';

    /**
     * 根据用户申请宰杀记录id查询数据
     *
     * @param int   $userSlaughterRecordsId
     * @param array $fields
     * @return array
     */
    public function getItemByUserSlaughterRecordsId(int $userSlaughterRecordsId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        $result =  $this->select($fields)
            ->where('user_slaughter_records_id', $userSlaughterRecordsId)
            ->where('deleted', self::DELETED_NO)
            ->first();
        return $result ? $result->toArray() : [];
    }

    /**
     * 根据用户申请宰杀记录ids查询数据
     *
     * @param array   $userSlaughterRecordsIds
     * @param array $fields
     * @return array
     */
    public function getItemByUserSlaughterRecordIds(array $userSlaughterRecordsIds, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
            ->join("slaughter_express", 'slaughter_send_back_records.slaughter_express_id', '=', 'slaughter_express.id')
            ->whereIn('user_slaughter_records_id', $userSlaughterRecordsIds)
            ->where('slaughter_send_back_records.deleted', self::DELETED_NO)
            ->get()
            ->toArray();
    }
}
